#!/bin/bash

MAP_WRITER_LINK=lib/default/map-writer.jar
MAP_WRITER_LIB_INSTALL=/home/art/Documents/PFC2/osmosis-capat/lib/mapsforge-map-writer-0.3.0-jar-with-dependencies.jar
LIB=lib/default

CLEAR=clear

if [ "$1" = $CLEAR ];
then
    echo "Clearing the lib"
    rm -f $LIB/aopalliance-1.0.jar
    rm -f $LIB/commons-codec-1.5.jar
    #rm -f $LIB/commons-compress-1.2.jar
    rm -f $LIB/commons-dbcp-1.4.jar
    #rm -f $LIB/commons-logging-1.1.1.jar
    rm -f $LIB/commons-pool-1.5.4.jar
    rm -f $LIB/jpf-1.5.jar
    #rm -f $LIB/map-writer.jar
    rm -f $LIB/mysql-connector-java-5.1.18.jar
    rm -f $LIB/osmosis-apidb-*.jar
    rm -f $LIB/osmosis-areafilter-*.jar
    #rm -f $LIB/osmosis-core-*.jar
    rm -f $LIB/osmosis-dataset-*.jar
    rm -f $LIB/osmosis-extract-*.jar
    rm -f $LIB/osmosis-hstore-*.jar
    #rm -f $LIB/osmosis-pbf-*.jar
    rm -f $LIB/osmosis-pgsimple-*.jar
    rm -f $LIB/osmosis-pgsnapshot-*.jar
    rm -f $LIB/osmosis-replication-*.jar
    rm -f $LIB/osmosis-set-*.jar
    rm -f $LIB/osmosis-tagfilter-*.jar
    #rm -f $LIB/osmosis-xml-*.jar
    #rm -f $LIB/osmpbf-*.jar
    #rm -f $LIB/plexus-classworlds-2.4.jar
    rm -f $LIB/postgis-jdbc-1.3.3.jar
    rm -f $LIB/postgresql-9.0-801.jdbc4.jar
    #rm -f $LIB/protobuf-java-2.4.1.jar
    rm -f $LIB/spring-aop-3.0.6.RELEASE.jar
    rm -f $LIB/spring-asm-3.0.6.RELEASE.jar
    rm -f $LIB/spring-beans-3.0.6.RELEASE.jar
    rm -f $LIB/spring-context-3.0.6.RELEASE.jar
    rm -f $LIB/spring-core-3.0.6.RELEASE.jar
    rm -f $LIB/spring-expression-3.0.6.RELEASE.jar
    rm -f $LIB/spring-jdbc-3.0.6.RELEASE.jar
    rm -f $LIB/spring-tx-3.0.6.RELEASE.jar
    rm -f $LIB/stax2-api-3.1.1.jar
    rm -f $LIB/woodstox-core-lgpl-4.1.2.jar
    #rm -f $LIB/xercesImpl-2.9.1.jar
else
    echo "Not cleaning the lib"
fi

if [ ! -f $MAP_WRITER_LINK ];
then
	echo "Creating a link to the mapsforge-map-witer tuned library" &&
	cp $MAP_WRITER_LIB_INSTALL $MAP_WRITER_LINK
fi

./bin/osmosis -plugin org.openstreetmap.osmosis.core.CorePluginLoader -plugin crosby.binary.osmosis.BinaryPluginLoader -plugin org.openstreetmap.osmosis.xml.XmlPluginLoader -plugin org.mapsforge.map.writer.osmosis.MapFileWriterPluginLoader --rb file=data/andorra.osm.pbf --mapfile-writer file=/tmp/andorra.map type=hd &&
./bin/osmosis -plugin org.openstreetmap.osmosis.core.CorePluginLoader -plugin crosby.binary.osmosis.BinaryPluginLoader -plugin org.openstreetmap.osmosis.xml.XmlPluginLoader -plugin org.mapsforge.map.writer.osmosis.MapFileWriterPluginLoader --read-xml file="data/map.osm" --mapfile-writer file="/tmp/arbucies.map" bbox=2.47,41.80,2.54,41.84 type=hd &&

adb push /tmp/andorra.map /sdcard/download/my_andorra.map &&
adb push /tmp/arbucies.map /sdcard/download/my_arbucies.map
